define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sys/notice/index' + location.search,
                    add_url: 'sys/notice/add',
                    edit_url: 'sys/notice/edit',
                    del_url: 'sys/notice/del',
                    multi_url: 'sys/notice/multi',
                    import_url: 'sys/notice/import',
                    export_url: 'sys/notice/export',
                    table: 'tk_bdl_sys_notice',
                }
            });

            var table       = $("#table");
            var showExport  = $(".btn-export").data('value')

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                fixedColumns: true,
                fixedRightNumber: 1,
                showToggle: false,
                showExport: showExport,
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'ID',operate:false},

                        {field: 'fenable', title: '使用状态', searchList: {"1":'可用',"0":'禁用'}, formatter: Table.api.formatter.toggle}  ,
                        {field: 'fk_bdl_title', title: '公告标题', operate: 'LIKE'},

                        {field: 'fk_bdl_isindex', title: '是否首页轮播', searchList: {"0":'否',"1":'是'}, formatter: Table.api.formatter.label}  ,

                        {field: 'fk_bdl_comment', title: '备注', operate: 'LIKE'},




                        {field: 'fk_bdl_creatorid', title: '创建人',operate: false,visible:false,},
                        {field: 'creator.nickname', title: '创建人', operate: 'LIKE',visible:false},
                        {field: 'fk_bdl_createtime', title: '创建时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'fk_bdl_fmodifierid', title: '修改人',operate: false,visible:false,},
                        {field: 'modifier.nickname', title: '修改人', operate: 'LIKE',visible:false},
                        {field: 'fk_bdl_modifytime', title: '修改时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false},

                        {field: 'operate', title: '操作', table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'sys/notice/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'fenable', title: '使用状态', searchList: {"1":'可用',"0":'禁用'}, formatter: Table.api.formatter.toggle}  ,
                        {field: 'fk_bdl_title', title: '公告标题', operate: 'LIKE'},

                        {field: 'fk_bdl_isindex', title: '是否首页轮播', searchList: {"0":'否',"1":'是'}, formatter: Table.api.formatter.label}  ,

                        {field: 'fk_bdl_comment', title: '备注', operate: 'LIKE'},
                        {
                            field: 'fk_bdl_deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'sys/notice/restore',
                                    refresh: true
                                }
                                // ,
                                // {
                                //     name: 'Destroy',
                                //     text: __('Destroy'),
                                //     classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                //     icon: 'fa fa-times',
                                //     url: 'bdl/other/problemlist/destroy',
                                //     refresh: true
                                // }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function ()
        {
            Controller.api.bindevent();
        },
        edit: function ()
        {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };


    return Controller;
});
